package com.dev;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.ProgressBar;
import android.graphics.Typeface;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.View;

public class AlertTabLoading extends LinearLayout implements OnClickListener{
    WindowManager.LayoutParams wlp=new WindowManager.LayoutParams();
	LinearLayout titlebar;
	TextView title;
    TextView message;
    ProgressBar indeterminate;
    IconViewClose close;
    MainActivity ma;
    TabLoader tabLoader;
    AlertTabLoading(MainActivity ma){
		super(ma);
        this.ma=ma;
        setOrientation(1);
        setBackground(new GUI.BorderDrawable());
		title=new TextView(ma);
		title.setText("正在恢复标签页。。。");
        close=new IconViewClose(ma);
        close.setOnClickListener(this);
        titlebar=new LinearLayout(ma);
        titlebar.setOrientation(0);
        titlebar.addView(title,new LinearLayout.LayoutParams(0,-1,1f));
        titlebar.addView(close);
        titlebar.setBackground(new GUI.BorderDrawable());
        indeterminate=new ProgressBar(ma);
        message=new TextView(ma);
        message.setTypeface(Typeface.MONOSPACE);
        message.setTextColor(0xff000000);
        message.setTextSize(13);
        addView(titlebar,-1,ma.dialogTitleBarHeight);
        addView(indeterminate,-1,-2);
        addView(message,-1,-2);
	}
    void show(){
        wlp.width=ma.wp*4/5;
        ma.wm.addView(this,wlp);
        tabLoader=new TabLoader();
        tabLoader.start();
    }

    @Override
    public void onClick(View v) {
        if(v==close){
            ma.wm.removeView(this);
            tabLoader.interrupt();
        }
    }
    class TabLoader extends Thread {
        AlertTabLoading atl;
        TabLoader(){
            atl=new AlertTabLoading(ma);
            atl.show();
        }
        @Override
        public void run() {
            super.run();
            ma.runOnUiThread(new Runnable(){
                    public void run(){
                        ma.wm.removeView(atl);
                    }
                });
        }
    }
}
